#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单的数学运算MCP服务
"""

from mcp.server.fastmcp import FastMCP

# 创建MCP服务实例
mcp = FastMCP("Math Calculator")

@mcp.tool()
def add(a: float, b: float) -> str:
    """加法运算"""
    try:
        result = a + b
        return f"{a} + {b} = {result}"
    except Exception as e:
        return f"加法运算错误: {str(e)}"

@mcp.tool()
def subtract(a: float, b: float) -> str:
    """减法运算"""
    try:
        result = a - b
        return f"{a} - {b} = {result}"
    except Exception as e:
        return f"减法运算错误: {str(e)}"

@mcp.tool()
def multiply(a: float, b: float) -> str:
    """乘法运算"""
    try:
        result = a * b
        return f"{a} × {b} = {result}"
    except Exception as e:
        return f"乘法运算错误: {str(e)}"

@mcp.tool()
def divide(a: float, b: float) -> str:
    """除法运算"""
    try:
        if b == 0:
            return "错误: 除数不能为零"
        result = a / b
        return f"{a} ÷ {b} = {result}"
    except Exception as e:
        return f"除法运算错误: {str(e)}"

# 启动服务
if __name__ == "__main__":
    mcp.run(transport="stdio")